	var IfStatusData = [{
		id:'',
		name:'全部',
		'selected':'true'
	},{
		id:'0',
		name:'停用'
	},{
		id:'1',
		name:'启用'
	}];
	
	var IfAuditStatusData = [{
		id:'',
		name:'全部',
		'selected':'true'
	},{
		id:'0',
		name:'未审核'
	},{
		id:'1',
		name:'已审核'
	}];	
$(document).ready(function(){
		$('#win').window('close');
		$('#comboxSearchField').combobox({
			url: BASE_URL_FIELD_SEARCH + '/findAllOfCurrentUserCanManage' + '?v=' + Math.random(),
			valueField: 'id',
		    textField: 'name',
		    editable: false,
		    method:'get',
		    loadFilter: function(data){
		    	var allCheck = {'id':'','name':'全部'};
		    	data.content.unshift(allCheck);
		    	return data.content;
		    },
		    onSelect: function(record){
		    	comboxSearchSystemName.combobox({
                    disabled: false,
                    method:'get',
                    queryParams: {fieldId: record.id},
                    url: BASE_URL_FIELD_SYSTEM_SEARCH +'/findByFieldOfCurrentUserCanManage' + '?v=' + Math.random(),
                    valueField: 'id',
                    textField: 'name',
					data:'',
        		    loadFilter: function(data){
        		    	var allCheck = {'id':'','name':'全部'};
        		    	data.content.unshift(allCheck);
        		    	return data.content;
        		    },
        		    onLoadSuccess:function(){
        		    	comboxSearchSystemName.combobox('setValue','');
        		    }
                }).load();
		    },
		    onLoadSuccess:function(){
		    	$('#comboxSearchField').combobox('setValue','');
		    }
		});
		
		//所属系统下拉框
		var comboxSearchSystemName = $('#comboxSearchFieldSystem').combobox({
            disabled: true,
            valueField: 'id',
            textField: 'name',
            editable: false,
            data:[{id:'',name:'全部','selected':'true'}]
        });
		
		var comboxInterfaceStatus = $('#comboxInterfaceStatus').combobox({
            valueField: 'id',
            textField: 'name',
            editable: false,
		  	data:IfStatusData
        });
		
		
		var comboxAuditStatus = $('#comboxAuditStatus').combobox({
            valueField: 'id',
            textField: 'name',
            editable: false,
		  	data:IfAuditStatusData,
		  	onLoadSuccess:function(){
		    	$('#comboxAuditStatus').combobox('setValue','0');
		    }
        });
		
		$("#auditResult").datagrid({
			url : '',
			method:'get',
			autoRowHeight:true,
			singleSelect:true,
			striped:true,
			nowrap:false,
			columns:[[
						{field:'ifName',title:'接口名称',width:140},
						{field:'ifAuditDes',title:'审核结果描述',width:130}
			      ]]
		});
		
		$("#datagrid").datagrid({
			url : BASE_URL_HTTP_INTERFACE_SEARCH + '/findInterfacesByUser?v='+Math.random(),
			method:'get',
			autoRowHeight:true,
			singleSelect:false,
			striped:true,
			nowrap:false,
			pageSize:20,
			pageList:[10,20,50,100],
			columns:[[
			          	{field:'',width:10,checkbox:true},
						{field:'fieldName',title:'领域',width:60},
						{field:'systemName',title:'系统',width:60},
						{field:'interfaceType',title:'接口类型',width:100,align:'left'},
						{field:'interfaceName',title:'接口名称',width:115,align:'left'},
						{field:'interfaceCode',title:'接口编码',width:115,align:'left'},
						{field:'createdDate',title:'注册时间',width:150},
						{field:'auditStatus',title:'审核状态',width:60},
						{field:'interfaceVersion',title:'版本',width:70},
						{field:'bundleName',title:'bundle编号',width:100},
						{field:'interfaceStatus',title:'操作',width:100,
							formatter: function(value,row,index){
								if(value == 0){
									if(row.auditStatus == "已审核"){
										return '<a href="#" class="default_btn" style="width:70%;float:left;color:#999; border: 1px solid #999; cursor: default;" onclick="">审核</a>';
										/*<a href="#" class="default_btn" style="width:35%;display: block;float:right;" onclick="changeIfStatus(\'' + index+ '\')">启用</a>*/
									}else{
										return '<a href="#" class="default_btn" style="width:70%;float:left;" onclick="changeIfAuditStatus(\'' + index+ '\')" >审核</a>';
										/*<a href="#" class="default_btn" style="width:35%;display: block;float:right;color:#999; border: 1px solid #999; cursor: default;" >启用</a>*/
									}
								}else if(value == 1){
									if(row.auditStatus == "已审核"){
										return '<a href="#" class="default_btn" style="width:70%;float:left;color:#999; border: 1px solid #999; cursor: default;" onclick="">审核</a>';
										/*<a href="#" class="default_btn" style="width:35%;display: block;float:right;" onclick="changeIfStatus(\'' + index+ '\')">停用</a>';
*/									}else{
										return '<a href="#" class="default_btn" style="width:70%;float:left;" onclick="changeIfAuditStatus(\'' + index+ '\')" >审核</a>';
										/*<a href="#" class="default_btn" style="width:35%;display: block;float:right;color:#999; border: 1px solid #999; cursor: default;" >停用</a>';
*/									}
									
								}else{
									return "";
								}
							}
						}
			      ]],
			pagination:true,
			loadFilter:function(data){
				//alert("inData:"+JSON.stringify(data));
				return {
					total: data.totalElements,
					rows: data.content
				};
			},
			onBeforeLoad:function(param){
				param.page -= 1;
				param.size = param.rows;
				delete param.rows;
				
				param.sort = 'createTime,desc';
				var fieldId = $('#comboxSearchField').combobox('getValue');
				if(fieldId !=""){
					param.fieldId = fieldId;
				}else{
					param.fieldId = "";
				}
				
				var fieldSystemId = $('#comboxSearchFieldSystem').combobox('getValue');
				if(fieldSystemId !=""){
					param.fieldSystemId = fieldSystemId;
				}else{
					param.fieldSystemId = "";
				}
				var Status = $('#comboxInterfaceStatus').combobox('getValue');
				if(Status !=""){
					param.Status = Status;
				}else{
					param.Status = "";
				}
				
				var auditStatus = $('#comboxAuditStatus').combobox('getValue');
				if(auditStatus !=""){
					param.auditStatus = auditStatus;
				}else{
					param.auditStatus = "";
				}
				 
				var name = $('#interfaceName').val();
				if(name !=""){
					param.name = name;
				}else{
					param.name = "";
				}
				var code = $('#serachInterfaceCode').val();
				if(code !=""){
					param.code = code;
				}else{
					param.code = "";
				}
				param["createTime"] = $("#txtCreateTimeBeg").datetimebox('getValue');
				param["endTime"] = $("#txtCreateTimeEnd").datetimebox('getValue');
			}
		});
		
		$("#datagrid").datagrid('getPager').pagination({   
		    displayMsg:'当前显示从 [{from}] 到 [{to}] 共[{total}]条记录'
		}); 
		
		$(".button_con a" ).removeClass("l-btn-plain");
	});
	
	//修改接口的审核状态
	function changeIfAuditStatus(index){
		var row = $('#datagrid').datagrid('getRows')[parseInt(index, 10)];
		var jsonData = {
				id:row.interfaceId,
				interfaceType:row.type
		}
		$("#progressbar, #progressbar_tips").fadeIn();
		loading_point.timer = setInterval(loading,200);
		$.ajax({
  			type: "get",
  			url: BASE_URL_HTTP_INTERFACE + '/updateInterfaceAuditStatus' + '?v=' + Math.random(),
  			dataType:'json',
  			data: jsonData,
  			contentType:"application/json",
  			success: function(result) {
  				$("#progressbar, #progressbar_tips").fadeOut();
				clearInterval(loading_point.timer);
  				//alert("result" + result.backValue);
  				if(result.backValue == true){
	  					$.messager.alert('提示','<p>审核成功</p>','info',function(){
	  						$('#datagrid').datagrid('reload');
	  					});
  				}else if(result.backValue == false){
  					$.messager.alert('错误','<p>' + result.errorDes + '</p>','error',function(){
  						$('#datagrid').datagrid('reload');
  					});
  				}
  				else{
  				}
  			},
  			error: function() {
  				$("#progressbar, #progressbar_tips").fadeOut();
				clearInterval(loading_point.timer);
  				$.messager.alert('错误','<p>服务异常，审核失败，请稍后重试或联系管理员!</p>', 'error');
  			}
  		});
	}
	
	//一次审核多个接口
	function onAudits(){
		var httpIds  = "";
		var ftpIds = "";
		var rows = $('#datagrid').datagrid('getChecked'); 
		if(rows.length == 0){
 			$.messager.alert('警告',"<p>请选中要审核的记录!</p>","warning");
 			return ;
 		}
		for(var i = 0; i <　rows.length; i++){
			if(rows[i].type === '3'){
				//ftp接口
				if(rows[i].auditStatus === '未审核'){
					ftpIds += (ftpIds == ""?"":",") + rows[i].interfaceId;
				}
			}else{
				//http接口
				if(rows[i].auditStatus === '未审核'){
					httpIds += (httpIds == ""?"":",") + rows[i].interfaceId;
				}
			}
			
		}
		
		var jsonData = {
				httpIds:httpIds,
				ftpIds:ftpIds,
		}
		
		$("#progressbar, #progressbar_tips").fadeIn();
		loading_point.timer = setInterval(loading,200);
		
		$.ajax({
  			type: "get",
  			url: BASE_URL_HTTP_INTERFACE + '/batchAuditIfStatus' + '?v=' + Math.random(),
  			dataType:'json',
  			data: jsonData,
  			contentType:"application/json",
  			success: function(result) {
  				$("#progressbar, #progressbar_tips").fadeOut();
				clearInterval(loading_point.timer);
				
  				var auditData = {
  						total:"",
  						rows:result.auditResult
  				}
  				$("#auditResult").datagrid('loadData', auditData);
  				
  				$('#win').window('open');
  			},
  			error: function() {
  				$("#progressbar, #progressbar_tips").fadeOut();
				clearInterval(loading_point.timer);
  				$.messager.alert('错误','<p>服务异常，审核失败，请稍后重试或联系管理员!</p>', 'error');
  			}
  		});
	}
	
	//查询
	function onSearch(){
		$('#datagrid').datagrid('reload');
	}
	
	
	var loading_point = {
			timer:null,
			len:3,
			count:0
		};
	function loading()
	{
	 	if(loading_point.count < loading_point.len)
		{
			loading_point.count++;
			$("#progressbar_point").text($("#progressbar_point").text() + ".");
		}else
		{
			loading_point.count = 0;
			$("#progressbar_point").text("");
		}	
	}
	
	
	function onSure(){
		$('#auditResult').datagrid('loadData', { total: 0, rows: [] });
		$('#win').window('close');
		$('#datagrid').datagrid('reload');
	}
	
	